/**
 * 实现可以接受无限参数的柯里化函数
*/

function currying(fn) {
  const args = []
  return function result(...rest) {
    if (!rest.length) {
      return fn(...args)
    }
    args.push(...rest)
    return result
  }
}

const add = (...args) => args.reduce((a, b) => a + b)
const sum = currying(add)
console.log(sum(1)(2)(3)(4)())